<template>
	<view class="jiaogefahuo">
		<view v-if="addressData == null" class="addressNO" @click="handleAddress">
			<view class="left">
				<u-icon name="plus-circle" color="#359691" size="20"></u-icon>
				<view class="" style="margin-left: 26rpx;">
					添加收货人
				</view>
			</view>
			<image src="../../static/image/right.png" mode="" style="width: 14.88rpx;height: 28rpx;"></image>
		</view>
		<view v-else class="addressBox" @click="handleAddress">

			<view class="left">
				<view class="nameandpphone">
					<view class="">
						{{addressData.name}}
					</view>
					<view class="" style="margin: 0 20rpx;">
						{{addressData.phone}}
					</view>
					<view v-if="addressData.type == '0'" class="defult">
						默认
					</view>
				</view>
				<view class="positions">
					{{addressData.address}}
				</view>
			</view>
			<image src="../../static/image/right.png" mode="" style="width: 14.88rpx;height: 28rpx;"></image>
		</view>


		<view class="dataListitem">
			<view class="bianhao">
				<!-- 订单编号:{{pageData.order_no}} -->
			</view>
			<view class="content">
				<image :src="pageData.image" mode="" style="width: 170rpx; height: 170rpx;border-radius: 10rpx;">
				</image>
				<view class="contentRight">
					<view class="name">
						{{pageData.name}}
					</view>
					<view class="price">
						拍中价格:￥{{pageData.all_price}}
					</view>
					<view class="maijia">
						<view class="maijiatext">
							卖家
						</view>
						<view class="maijianame">
							{{pageData.nickname}}：<!-- 15512345678 -->
						</view>
					</view>
				</view>
			</view>
			<view class="heng"></view>
			<view class="time">
				下单时间:{{pageData.created_at}}
			</view>
			<view class="itemBottom">
				<view class="itemBottomleft">
					待支付：{{pageData.all_price}}
				</view>
			</view>
		</view>

		<view class="btns" @click="$u.debounce(handledeliverygoods, 500)">
			提交发货
		</view>


	</view>
</template>

<script>
	import {
		buyorderdetail,
		getuserarea,
		deliverygoods
	} from "@/api/api.js"
	export default {
		data() {
			return {
				pageId: null,
				pageData: {
					name: ""
				},
				addressData: null,
				default: false
			}
		},
		onLoad(options) {
			if (!uni.getStorageSync("token")) {
				uni.reLaunch({
					url: "../login/index"
				})
				return
			}
			if (options.id) {
				this.pageId = options.id
				this.handlebuyorderdetail()
				this.handlegetuserarea()
			}

		},
		onShow() {
			if (uni.getStorageSync("address")) {
				this.addressData = uni.getStorageSync("address")
			}
		},
		methods: {
			async handlebuyorderdetail() {
				let res = await buyorderdetail({
					id: this.pageId,
				})
				console.log("买品详情", res)
				this.pageData = res.data

			},

			async handlegetuserarea() {
				let res = await getuserarea()
				res.data.forEach((item, index) => {
					if (item.type == '0') {
						this.addressData = item
						this.default = true
					}
				})
				console.log("接口地址", this.addressData)
			},
			async handledeliverygoods() {
				let res = await deliverygoods({
					id: this.pageId,
					area_id: this.addressData.id
				})
				console.log("2",res)
				if (res.code == 1000) {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 1500
					});

				} else {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 1500
					});
				}
			},
			handleAddress() {
				uni.navigateTo({
					url: `./address?orderId=${this.pageId}`
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.addressNO {
		width: 100%;
		height: 119rpx;
		background: #FFFFFF;
		padding: 35rpx 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.left {
			display: flex;
			align-items: center;
			font-size: 30rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: 600;
			color: #091535;
			line-height: 42rpx;
		}
	}

	.addressBox {
		width: 100%;
		height: 161rpx;
		background: #FFFFFF;
		padding: 24rpx 32rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 400;
		color: #707070;
		line-height: 36rpx;

		.left {
			.nameandpphone {
				display: flex;
				align-items: center;

				.defult {
					width: 56rpx;
					height: 26rpx;
					background: #359691;
					border-radius: 2rpx 2rpx 2rpx 2rpx;
					font-size: 20rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					line-height: 26rpx;
					text-align: center;
				}
			}

			.positions {
				margin-top: 18rpx;
			}
		}
	}

	.dataListitem {
		width: 100%;
		height: 384rpx;
		background: #FFFFFF;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
		margin-bottom: 30rpx;
		padding: 18rpx 30rpx;
		box-sizing: border-box;
		margin: 0 auto;
		margin-top: 14rpx;

		.bianhao {
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 400;
			color: #707070;
			line-height: 28rpx;
		}

		.content {
			display: flex;
			width: 100%;
			margin-top: 20rpx;

			.contentRight {
				height: 170rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				margin-left: 30rpx;

				.name {
					font-size: 28rpx;
					font-family: PingFang SC-Bold, PingFang SC;
					font-weight: 400;
					color: #333333;
					line-height: 28rpx;
				}

				.price {
					font-size: 28rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 400;
					color: #707070;
					line-height: 28rpx;
				}

				.maijia {
					display: flex;
					height: 36rpx;
					border-radius: 0rpx 0rpx 0rpx 0rpx;
					opacity: 1;
					border: 2rpx solid #359691;

					.maijiatext {
						width: 78rpx;
						height: 36rpx;
						background: #359691;
						color: #ffffff;
						font-size: 28rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
						line-height: 36rpx;
						text-align: center;
					}

					.maijianame {
						width: 292rpx;
						font-size: 28rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 400;
						color: #707070;
						line-height: 36rpx;
						text-align: center;
					}
				}
			}
		}

		.heng {
			width: 100%;
			height: 1rpx;
			background-color: #D8D8D8;
			margin-top: 20rpx;
		}

		.time {
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 400;
			color: #707070;
			line-height: 28rpx;
			margin-top: 20rpx;
		}

		.itemBottom {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-top: 20rpx;

			.itemBottomleft {
				font-size: 30rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 400;
				color: #333333;
				line-height: 28rpx;
			}

		}
	}

	.btns {
		width: 542rpx;
		height: 80rpx;
		background: #04767C;
		border-radius: 512rpx 512rpx 512rpx 512rpx;
		font-size: 36rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 80rpx;
		text-align: center;
		margin: 0 auto;
		margin-top: 268rpx;
	}
</style>